package ${package}.controller;

import ${package}.entity.${entityName};
import ${package}.dto.${entityName}QueryDTO;
import ${package}.service.${entityName}Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

@RestController
@RequestMapping("/${table.name}")
@RequiredArgsConstructor
@Api(tags = "${table.comment}管理")
public class ${entityName}Controller {

    private final ${entityName}Service ${CodeGeneratorUtils.toCamelCase(entityName, false)}Service;

    @GetMapping
    @ApiOperation("分页查询")
    public IPage<${entityName}> page(${entityName}QueryDTO queryDTO) {
        return ${CodeGeneratorUtils.toCamelCase(entityName, false)}Service.page(queryDTO);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询")
    public ${entityName} getById(@PathVariable Long id) {
        return ${CodeGeneratorUtils.toCamelCase(entityName, false)}Service.getById(id);
    }

    @PostMapping
    @ApiOperation("新增")
    public void save(@RequestBody @Valid ${entityName} entity) {
        ${CodeGeneratorUtils.toCamelCase(entityName, false)}Service.save(entity);
    }

    @PutMapping
    @ApiOperation("修改")
    public void update(@RequestBody @Valid ${entityName} entity) {
        ${CodeGeneratorUtils.toCamelCase(entityName, false)}Service.update(entity);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public void delete(@PathVariable Long id) {
        ${CodeGeneratorUtils.toCamelCase(entityName, false)}Service.delete(id);
    }
}